Add local LLM support via Ollama and vLLM providers - #4
Open
Waynting wants to merge 1 commit into
Open
Conversation
- Add "ollama" and "vllm" entries to the chat, slow-chat, and embedding LiteLLM routers, configurable via environment variables (OLLAMA_*/VLLM_*) - Move load_dotenv() before router construction so .env settings apply - Enable native JSON response_format for ollama/vllm providers - Add LLM_MAX_TOKENS cap for backends with smaller context windows - Add EMBEDDING_PROVIDER override to mix providers (e.g. vLLM chat + Ollama embeddings) - Document local model setup in README Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
I've been researching LLM-agent-based usability testing recently, and given how capable local open-weight models have become, it seemed like UXAgent could realistically run on fully local models — no cloud API keys, easier to iterate on experiments, and lower cost for large batch runs. Since the docstring in
async_chatalready hints at adding custom providers through the LiteLLM routers, I followed that path and added first-class support for Ollama and vLLM.Changes
agent/gpt.pyollamaandvllmentries (plus_thinkingvariants) to the chat, slow-chat, and embedding LiteLLM routers. Models and endpoints are configurable via environment variables (OLLAMA_CHAT_MODEL,OLLAMA_SLOW_CHAT_MODEL,OLLAMA_EMBEDDING_MODEL,VLLM_API_BASE,VLLM_CHAT_MODEL, …) with sensible defaults.load_dotenv()before router construction — previously it ran after the routers were built, so.envsettings never applied to them.response_formatfor the ollama/vllm providers (both backends support it, and it significantly improves JSON reliability for local models). The existing regex-extraction fallback is unchanged.LLM_MAX_TOKENSenv cap:async_chatdefaults tomax_tokens=64000, which vLLM rejects with a 400 when it exceeds the served model's context length.EMBEDDING_PROVIDERenv override so chat and embeddings can use different providers (a vLLM server typically serves a single model, so e.g. vLLM chat + Ollama embeddings).conf/base.yaml: documented the new provider options forllm_provider.README.md: added a "Using local models (Ollama / vLLM)" section, including the Ollama context-window caveat and notes on model-size requirements.No agent logic was touched, and the three existing cloud providers (
openai/aws/anthropic) behave exactly as before.Testing
Verified end-to-end with all cloud API keys removed from the environment:
llama3.1+nomic-embed-text):async_chat(fast + slow routers),json_mode, syncchat, andembed_textall pass.hosted_vllm/) validated against an OpenAI-compatible endpoint, including theLLM_MAX_TOKENScap and JSON mode.EMBEDDING_PROVIDERoverride (vllm chat + ollama embeddings) works.ruff checkpasses.🤖 Generated with Claude Code